package ch.ti.bfh.app.loodel.internal.security;

import ch.ti.bfh.app.loodel.domain.member.Member;
import ch.ti.bfh.app.loodel.domain.member.MemberRepository;
import ch.ti.bfh.app.loodel.service.UserContext;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class DefaultInternalUserContext implements InternalUserContext {

    @Resource
    private MemberRepository memberRepository;

    @Resource
    private UserContext userContext;

    public DefaultInternalUserContext() {
    }

    @Override
    public Member getCurrentMember() {
        return memberRepository.findByEmail(userContext.getCurrentUser().getMember().geteMail());
    }
}
